#ifndef RENDERER_HPP_INCLUDE
#define RENDERER_HPP_INCLUDE

#include <map>
#include <vector>
#include <memory>
#include <utility>
#include <time.h>

#include "types.hpp"
#include "raster.hpp"
#include "primitives.hpp"
#include "shaders.hpp"
#include "object.h"

class Primitive;
class SurfacePrimitive;
class Object;

struct SampleInfo
{
	Vector3 position;
	Ray ray;
	double dist;
	int depth;
	int reflectionDepth;
	int refractionDepth;
	int giDepth;
	SampleInfo* prevSample;
	const Primitive* prim;

	int miscInt;
	Vector3 miscVector3;

	SampleInfo();
};

class Scene
{
public:
	typedef vector<const Primitive*> PrimVector;
	typedef PrimVector::const_iterator PrimIter;
private:
	 PrimVector primitives_;
public:
//	~Scene();
	void addPrimitive(const Primitive* prim);
	void addPrimitive(SurfacePrimitive* prim, const SurfaceShader* sh);
	void addObject(Object * object);

	PrimIter begin() const;
	PrimIter end() const;
};

class Renderer
{
private:
	int width_, height_;
	const char* filename_;
	Raster* raster_;

	time_t lastSaveTime_;
	bool timeToWrite();

	Renderer();
public:
	Renderer(int width, int height, const char* filename);
	~Renderer();

	void render(const Scene& scene);
	Color raytrace(const Ray& ray, const SampleInfo& prevSample, const Scene& scene) const;
};

#endif //RENDERER_HPP_INCLUDE
